<?php
// +----------------------------------------------------------------------
// | Description: 菜单
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\logic\MemberMenuLogic;
use app\common\validate\MemberMenuValidate;
use app\common\controller\AdminAuthController;
use app\common\model\MemberMenu as MemberMenuModel;
use think\response\Json;

/**
 * Class MemberMenu
 * @package app\admin\controller
 * @property MemberMenuLogic $logic
 * @property MemberMenuValidate $validate
 */
class MemberMenu extends AdminAuthController
{
    /**
     * 初始化
     * @return bool|void
     */
    public function initialize()
    {
        parent::initialize();
        $this->validate = MemberMenuValidate::instance();
        $this->logic = MemberMenuLogic::instance();
        return TRUE;
    }

    /**
     * 数据列表
     * @return Json
     */
    /**
     * 数据列表
     * @return Json
     */
    public function index()
    {

        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $type = !empty($param['type']) ? $param['type'] : '';
        $data = $this->logic->getTreeList($type);
        return $this->json_responce(['list' => $data]);
    }

    /**
     * 数据详情
     * @return Json
     */
    public function read(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->getByID($param);
        return $this->json_responce($data);
    }

    /**
     * 新增数据
     * @return Json
     */
    public function save()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->createData($param);
        return $this->json_responce();
    }

    /**
     * 更新数据
     * @return Json
     */
    public function update(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->updateByID($param);
        return $this->json_responce();
    }

    /**
     * 删除单条数据
     * @return Json
     */
    public function delete(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->delByID($param);
        return $this->json_responce();
    }

    /**
     * 批量删除数据
     * @return Json
     */
    public function deletes(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->delByIDs($param);
        return $this->json_responce();
    }

    /**
     * 启用/禁用数据
     * @return Json
     */
    public function enables(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->enableByIDs($param);
        return $this->json_responce();
    }
}
